/*********************************tree**********************************************/
function spread_InvCommodityInfo(){
	$('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', '');
	    $('.tree li.parent_li > span').on('click', function (e) {
	        var children = $(this).parent('li.parent_li').find(' > ul > li');
	        if (children.is(":visible")) {
	            children.hide('fast');
	            $(this).attr('title', '').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
	        } else {
	            children.show('fast');
	            $(this).attr('title', '').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
	        }
	        e.stopPropagation();
	    });
}
function edit_InvCommodityInfo(code,pc){
	var url = create_url('invCommodityInfo-edit');
	var parm = {'code':code,'pc': pc};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'950px', height:'600px', open:true});
}

function delete_InvCommodityInfo(code){
	$.Zebra_Dialog('是否删除(注意:删除该项后，该项下的所有子项将一并删除)',{
				'type': 'question',
				'title': '警告' ,
				'buttons':[
				           {caption:'删除',callback:function() {
				        	 	var url = create_url('invCommodityInfo-delete');
								delete_InvCommodityInfo_OK(code, url);
				    		}},
				           {caption:'取消',callback:function(){}
				    	}]
				});
}

function delete_InvCommodityInfo_OK(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				sys_msg('删除成功');
				sys_load_handle('invCommodityInfo');
			} else {
				sys_msg('操作失败');
			}
		}
	});
}
function query_InvCommodityInfo(){
	var parm = $('#queryInvCommodityInfoFrom').serialize();
	var url = create_url('invCommodityInfo-query');
	sys_record_parm('invCommodityInfo',parm);
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#resultDiv').html(result);
		}
	});
}

function query_InvCommodityInfo(){
	var keyword = $("#keyWordName").val();
	if(keyword == ""){
		sys_load_handle('invCommodityInfo');
	}else{
		$("#resultDiv").textSearch(keyword,{markColor: "red"});
	}
}       
function display_InvCommodityInfo_in(obj){	
	var dis = obj.find("em.display");
		dis.show();
} 
function display_InvCommodityInfo_out(obj){	
	var dis = obj.find("em.display");
		dis.hide();
}  

/*********************************edit**********************************************/
function addEvent_InvCommodity_trShow(){
	var trs = $("tr[class='hid']"); 
		for(i = 0; i < trs.length; i++){ 
		    trs[i].style.display = ""; 
		} 
		var name = $("#name").val();
		$("#cName").val(name);
}

function addEvent_InvCommodity_trHide(){
	var trs = $("tr[class='hid']"); 
		for(i = 0; i < trs.length; i++){ 
		    trs[i].style.display = "none"; 
		} 
}

function addEvent_InvCommodity_TextKeyup(){
	var name = $("#name").val();
	$("#cName").val(name);
}

function save_InvCommodityInfo(){
	var parm = $('#tableInvCommodityInfo').serialize();
	var url = create_url('invCommodityInfo-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
		sys_submiting_close();
			if ('success' == result) {
				sys_msg('操作成功!');
				$.fn.colorbox.close();
				sys_load_handle('invCommodityInfo');
			}
		}
	});
}

function closeColorbox_InvCommdityInfo(){
	$.fn.colorbox.close();
}

function checked_InvCommodityInfo(){
	var name = $("#name").val();
	var price = $("#price").val();
	var rp = $('#rp').val();
	var un = $('#un1').val();
	if(un.length == 0 ){
		sys_msg('请输入计量单位!');
		return;
	}
	if(name.length == 0 ){
		sys_msg('请输入名称!');
		return;
	}
	if(isNaN(price)){
		sys_msg('请输入正确的商品价格！');
		return;
	}
	if(isNaN(rp)){
		sys_msg('请输入正确的零售价格！');
		return;
	}
	save_InvCommodityInfo();
}